// Job
// 
// 保佑没Bug 
//
// Created by AS on 2019/5/4. 
//
// Copyright © 2018 AS. All rights reserved.
// 

#import "MapViewController.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import "LocationManager.h"
@interface MapViewController ()<BMKMapViewDelegate>{
    BMKMapView *_mapView;
}
@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"地图";
    [self initMapView];
}

-(void)initMapView{

    _mapView = [[BMKMapView alloc]initWithFrame:self.view.frame];
    _mapView.mapType = BMKMapTypeStandard;
    
    _mapView.centerCoordinate = CLLocationCoordinate2DMake(self.latitude, self.longitude);
    _mapView.showsUserLocation = YES;
    [self.view addSubview:_mapView];
    BMKPointAnnotation *point = [[BMKPointAnnotation alloc]init];
    
    CLLocationCoordinate2D location = CLLocationCoordinate2DMake(self.latitude, self.longitude);
    point.coordinate = location;
    point.title = self.name;
    [_mapView addAnnotation:point];
    
    
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self;
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_mapView viewWillDisappear];
    _mapView.delegate = nil;
}
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation{
    
    BMKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:@"BMKAnnotationView"];
    if (!view) {
        view = [[BMKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"BMKAnnotationView"];
    }
    [view setSelected:YES animated:YES];
    return view;
}



/**
 *地图初始化完毕时会调用此接口
 *@param mapView 地图View
 */
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView{
    
}

/**
 *地图渲染完毕后会调用此接口
 *@param mapView 地图View
 */
- (void)mapViewDidFinishRendering:(BMKMapView *)mapView{
    
}

@end
